package net.wds.ssbus.modules.dbconfig.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.wds.ssbus.common.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import net.wds.ssbus.common.utils.PageUtils;
import net.wds.ssbus.modules.dbconfig.dao.TbDbModelColumnCommonlyDao;

import net.wds.ssbus.modules.dbconfig.entity.TbDbModelColumnCommonlyEntity;

import net.wds.ssbus.modules.dbconfig.service.TbDbModelColumnCommonlyService;
import net.wds.ssbus.modules.dbconfig.vo.TbDbModelColumnCommonlyVo;
import net.wds.ssbus.modules.dict.entity.TbBaseDictitemEntity;
import net.wds.ssbus.modules.dict.service.TbBaseDictitemService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



@Service("tbDbModelColumnCommonlyService")
public class TbDbModelColumnCommonlyServiceImpl extends ServiceImpl<TbDbModelColumnCommonlyDao, TbDbModelColumnCommonlyEntity> implements TbDbModelColumnCommonlyService {

    @Autowired
    TbBaseDictitemService tbBaseDictitemService;
    /**
     * 带分页功能通过id查询类型名称
     *
    * */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TbDbModelColumnCommonlyEntity> page = this.page(
                new Query<TbDbModelColumnCommonlyEntity>().getPage(params),
                new QueryWrapper<TbDbModelColumnCommonlyEntity>()
        );
        List<TbDbModelColumnCommonlyEntity> records = page.getRecords();
        List<TbDbModelColumnCommonlyVo> collect = records.stream().map(item -> {
            TbDbModelColumnCommonlyVo tbDbModelColumnCommonlyVo = new TbDbModelColumnCommonlyVo();
            BeanUtils.copyProperties(item, tbDbModelColumnCommonlyVo);
            TbBaseDictitemEntity dictitemServiceById = tbBaseDictitemService.getById(item.getType());
            tbDbModelColumnCommonlyVo.setTypeName(dictitemServiceById.getDescription());
            return tbDbModelColumnCommonlyVo;
        }).collect(Collectors.toList());
        IPage<TbDbModelColumnCommonlyVo> VoIPage = new Page<>();
        VoIPage.setCurrent(page.getCurrent());
        VoIPage.setPages(page.getPages());
        VoIPage.setSize(page.getSize());
        VoIPage.setRecords(collect);
        VoIPage.setTotal(page.getTotal());
        return new PageUtils(VoIPage);
    }
}